﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Forest.Cat.Domain.Services;
using Forest.Cat.Admin.Models;
using Forest.Cat.Admin.Models.Resumes;
using Forest.Cat.Domain;
using Forest.Cat.Domain.Entities.Resumes;
using Forest.Cat.Domain.Services.Resumes;
using Forest.Cat.Domain.Configuration;
using Forest.Web.Framework.UI;
using Forest.Cat.Domain.Services.Jobseekers;
using Forest.Core;
using Forest.Cat.Domain.Services.Compnaies;
using Forest.Cat.Domain.Shared.Validation;
using Forest.Cat.Domain.Shared;

namespace Forest.Cat.Admin.Controllers {
    public class ResumeController : BaseController {
        private const int _pageSize = 10;
        private readonly IResumeService _resumeService;
        private readonly IWorkContext _workcontext;
        private readonly IWorkExperienceService _workExperienceService;
        private readonly ILovService _lovService;
        private readonly ITrainingService _trainingService;
        private readonly ISkillService _skillService;
        private readonly ICertificationService _certificationService;
        private readonly IEducationService _educationService;
        private readonly IShieldedCompanyService _shieldedCompanyService;
        private readonly ICompanyService _companyService;

        #region Ctor
        public ResumeController(IResumeService resumeService, IWorkContext workcontext,
            IWorkExperienceService workExperienceService, ILovService lovService, ITrainingService trainingService,
            ISkillService skillService, ICertificationService certificationService, IEducationService educationService,
            IShieldedCompanyService shieldedCompanyService, ICompanyService companyService) {
            this._resumeService = resumeService;
            this._workcontext = workcontext;
            this._workExperienceService = workExperienceService;
            this._lovService = lovService;
            this._trainingService = trainingService;
            this._skillService = skillService;
            this._certificationService = certificationService;
            this._educationService = educationService;
            this._shieldedCompanyService = shieldedCompanyService;
            _companyService = companyService;
        }
        #endregion

        #region Resume
        public ViewResult ResumeAdd() {
            var model = new ResumeEditModel();

            // 采番
            model.Id = Guid.NewGuid();
            model.FullName = _workcontext.CurrentUser.FullName;
            model.Email = _workcontext.CurrentUser.Email;
            model.Mobile = _workcontext.CurrentUser.Mobile;
            model.IDCard = _workcontext.CurrentUser.IDCard;
            model.PrivacyStatus = 1;//默认公开
            SetResumeEditDropDownList(model);
            return View("ResumeEdit", model);
        }

        public ActionResult ResumeList(ResumePagingFilteringModel command) {
            var model = new ResumeListModel();

            // 处理分页
            // if ( command.PageSize <0)

            var resumes = _resumeService.GetResumes(this._workcontext.CurrentUser.Id);

            //model.PagingFilteringContext.LoadPagedList(resumes);

            model.Resumes = resumes
                .Select(x => {
                    var resumeModel = new ResumeModel();
                    PrepareResumeModel(resumeModel, x);
                    return resumeModel;
                })
                    .ToList();
            ViewBag.CurrentAction = "ResumeList";
            return View(model);
        }

        [NonAction]
        private void SetResumeEditDropDownList(ResumeEditModel model) {
            // 性别
            var listGender = _lovService.GetLovByParentLabel("Gender").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.Genders = new SelectList(listGender, "Value", "Name", Convert.ToString(model.Gender));

            // 目前年薪
            var listSalaryRange = _lovService.GetLovByParentLabel("AnnualRevenue").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.SalaryRanges = new SelectList(listSalaryRange, "Value", "Name", Convert.ToString(model.CurrentRevenue));

            // 工作经验
            var listYearsOfExperience = _lovService.GetLovByParentLabel("YearsOfExperience").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.YearsOfExperiences = new SelectList(listYearsOfExperience, "Value", "Name",
                Convert.ToString(model.YearsOfExperience));

            // 最高学历
            var listEducationLevel = _lovService.GetLovByParentLabel("EducationLevel").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.EducationLevels = new SelectList(listEducationLevel, "Value", "Name",
                Convert.ToString(model.EducationLevel));

            // 户籍所在地
            // 居住地
            // 地点
            ViewBag.RegionalismList = _lovService.GetLovList(LovType.Regionalism).ToList();

            //JobCategoryList
            ViewBag.SubRegionalismList = _lovService.GetSubListByParentValue(LovType.Regionalism).ToList();

            // 语言能力1
            var listLanguage = _lovService.GetLovByParentLabel("Language").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.Language1s = new SelectList(listLanguage, "Value", "Name", Convert.ToString(model.Language1));
            ViewBag.Language2s = new SelectList(listLanguage, "Value", "Name", Convert.ToString(model.Language2));
            var listLevel = _lovService.GetLovByParentLabel("Level").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.Level1s = new SelectList(listLevel, "Value", "Name", Convert.ToString(model.Level1));
            ViewBag.Level2s = new SelectList(listLevel, "Value", "Name", Convert.ToString(model.Level2));

            // 公开设置
            ViewBag.PrivacyStatus = new List<SelectListItem>{
                new SelectListItem(){ Text = "公开",Value="1",Selected=model.PrivacyStatus==1?true:false},
                new SelectListItem(){ Text = "隐藏",Value="0",Selected=model.PrivacyStatus==0?true:false}
            };
        }

        [HttpPost]
        public ActionResult ResumeEdit(ResumeEditModel model) {
            if (ModelState.IsValid) {
                bool insert = false;
                var entity = _resumeService.GetResumeById(model.Id);
                if (entity == null) {
                    insert = true;
                    entity = new Resume();
                    entity.Id = _resumeService.CreateId;
                    entity.FullName = _workcontext.CurrentUser.FullName;
                    entity.IDCard = _workcontext.CurrentUser.IDCard;
                    entity.JobseekerId = _workcontext.CurrentUser.Id;
                    entity.DateCreated = DateTime.Now;
                }
                entity.City1 = model.City1;
                if (entity.City1.HasValue) {
                    var parent = _lovService.GetParent(model.City1.Value);
                    if (parent != null) {
                        entity.Province1 = parent.Value;
                    }
                }
                entity.City2 = model.City2;
                if (entity.City2.HasValue) {
                    var parent = _lovService.GetParent(model.City2.Value);
                    if (parent != null) {
                        entity.Province2 = parent.Value;
                    }
                }


                entity.ResumeName = model.ResumeName;
                entity.IDCard = model.IDCard;
                entity.FullName = model.FullName;
                entity.BirthDate = Convert.ToDateTime(model.BirthDateString);
                entity.Gender = model.Gender;
                entity.CurrentRevenue = model.CurrentRevenue;
                entity.YearsOfExperience = model.YearsOfExperience;
                entity.EducationLevel = model.EducationLevel;
                entity.Street2 = model.Street2;
                entity.BusLines = model.BusLines;
                entity.Language1 = model.Language1;
                entity.Language2 = model.Language2;
                entity.Level1 = model.Level1;
                entity.Level2 = model.Level2;
                entity.Tel = model.Tel;
                entity.Email = model.Email;
                entity.Mobile = model.Mobile;
                entity.PersonalSite = model.PersonalSite;
                entity.PrivacyStatus = model.PrivacyStatus;
                entity.LastUpdated = DateTime.Now;
                if (insert) {
                    Session["ResumeId"] = model.Id;
                    _resumeService.InsertResume(entity);
                }
                else {
                    _resumeService.UpdateResume(entity);
                }
                return RedirectToAction("ResumeOverview", new { id = entity.Id });
            }

            SetResumeEditDropDownList(model);
            return View(model);
        }

        public ViewResult ResumeEdit(Guid? Id) {
            var resumeId = Id ?? (Guid)Session["ResumeId"];

            var entity = _resumeService.GetResumeById(resumeId);
            var model = new ResumeEditModel() {
                BirthDate = entity.BirthDate,
                BusLines = entity.BusLines,
                CurrentRevenue = entity.CurrentRevenue,
                EducationLevel = entity.EducationLevel,
                Email = entity.Email,
                FullName = entity.FullName,
                Gender = entity.Gender,
                Id = entity.Id,
                IDCard = entity.IDCard,
                Language1 = entity.Language1,
                Language2 = entity.Language2,
                Level1 = entity.Level1,
                Level2 = entity.Level2,
                Mobile = entity.Mobile,
                PersonalSite = entity.PersonalSite,
                PostalCode = entity.PostalCode,
                Province1 = entity.Province1,
                City1 = entity.City1,
                City2 = entity.City2,
                Province2 = entity.Province2,
                Street2 = entity.Street2,
                Tel = entity.Tel,
                YearsOfExperience = entity.YearsOfExperience,
                ResumeName = entity.ResumeName,
                BirthDateString = entity.BirthDate.HasValue ? entity.BirthDate.Value.ToShortDateString() :
                            string.Empty,
                PrivacyStatus = entity.PrivacyStatus
            };

            SetResumeEditDropDownList(model);
            return View(model);
        }

        [HttpPost]
        public ActionResult ResumeDelete(Guid id) {
            //_resumeService.DeleteResumeAndDetial(id);
            _resumeService.MarkAsDeleted(id);
            return RedirectToAction("ResumeList");
        }

        public ActionResult ResumeOverview(Guid Id) {
            var item = _resumeService.GetResumeById(Id);
            var model = PrepareResumeModel(item);
            var works = _workExperienceService.GetWorkExperiences(Id);
            var trainings = this._trainingService.GetTrainings(Id);
            var skills = this._skillService.GetSkills(Id);
            var certifications = this._certificationService.GetCertifications(Id);
            var educations = this._educationService.GetEducations(Id);
            model.WorkExperiences = works.ToList().ConvertAll<WorkExperienceModel>(PrepareWorkModel);
            model.Trainings = trainings.ToList().ConvertAll<TrainingModel>(PrepareTrainingModel);
            model.Skills = skills.ToList().ConvertAll<SkillModel>(PrepareSkillModel);
            model.Certifications = certifications.ToList().ConvertAll<CertificationModel>(PrepareCertificationModel);
            model.Educations = educations.ToList().ConvertAll<EducationModel>(PrepareEducationModel);
            model.CareerGoal = PrepareCareerGoalModel(item);
            model.PrivacyStatus = item.PrivacyStatus;
            Session["ResumeId"] = Id;
            return View(model);
        }

        [HttpPost]
        public ActionResult ResumeRefresh(Guid resumeId) {
            var resume = _resumeService.GetResumeById(resumeId);
            resume.LastUpdated = DateTime.Now;
            _resumeService.UpdateResume(resume);
            return RedirectToAction("ResumeList");
        }

        [NonAction]
        private CareerGoalModel PrepareCareerGoalModel(Resume entity) {
            return new CareerGoalModel() {
                CurrentRevenue = entity.CurrentRevenue,
                CurrentRevenueName = entity.CurrentRevenue != null ? _lovService.GetLovName(entity.CurrentRevenue.Value)
                        : string.Empty,
                DesiredCompanyType = entity.DesiredCompanyType,
                DesiredCompanyTypeName = entity.DesiredCompanyType != null ? _lovService.GetLovName(entity.DesiredCompanyType.Value)
                    : string.Empty,
                DesiredIndustry = entity.DesiredIndustry,
                DesiredIndustryName = entity.DesiredIndustry.HasValue ? _lovService.GetLovName(entity.DesiredIndustry.Value)
                    : string.Empty,
                DesiredJobType = entity.DesiredJobType,
                DesiredJobTypeName = entity.DesiredJobType.HasValue ? _lovService.GetLovName(entity.DesiredJobType.Value)
                    : string.Empty,
                DesiredLocation = entity.DesiredLocation,
                DesiredLocationName = entity.DesiredLocation.HasValue ? _lovService.GetLovName(entity.DesiredLocation.Value)
                    : string.Empty,
                DesiredOccupation = entity.DesiredOccupation,
                DesiredOccupationName = entity.DesiredOccupation.HasValue ? _lovService.GetLovName(entity.DesiredOccupation.Value)
                    : string.Empty,
                DesiredSalary = entity.DesiredSalary,
                DesiredSalaryName = entity.DesiredSalary != null ? _lovService.GetLovName(entity.DesiredSalary.Value)
                       : string.Empty,
                Id = entity.Id
            };
        }

        [NonAction]
        private ResumeModel PrepareResumeModel(Resume item) {
            return new ResumeModel() {
                Id = item.Id,
                FullName = item.FullName,
                EducationLevel = item.EducationLevel,
                EducationLevelName = item.EducationLevel != null ? _lovService.GetLovName(item.EducationLevel.Value)
                                    : string.Empty,
                Province2 = item.Province2,
                City2 = item.City2,
                District2 = item.District2,
                Province2Name = item.Province2 != null ? _lovService.GetLovName(item.Province2.Value)
                                    : string.Empty,
                City2Name = item.City2 != null ? _lovService.GetLovName(item.City2.Value)
                                    : string.Empty,
                District2Name = item.District2 != null ? _lovService.GetLovName(item.District2.Value)
                                    : string.Empty,
                PersonalStatement = item.PersonalStatement
            };
        }
        #endregion

        #region 导航菜单
        /// <summary>
        /// 导航菜单
        /// </summary>
        /// <returns></returns>
        public PartialViewResult ResumeNavigation(String currentAction) {
            ViewBag.CurrentAction = currentAction;

            // 设定图片
            if (Session["ResumeId"] != null) {
                var id = (Guid)Session["ResumeId"];
                ViewBag.HasWorkExperiences = _workExperienceService.HasWorkExperiences(id);

                ViewBag.HasTrainings = _trainingService.HasTrainings(id);

                ViewBag.HasSkills = _skillService.HasSkills(id);

                ViewBag.HasCertifications = _certificationService.HasCertifications(id);

                ViewBag.HasEducations = _educationService.HasEducations(id);

                var entity = _resumeService.GetResumeById(id);
                ViewBag.HasCareerGoal = false;
                if (entity.DesiredJobType.HasValue || entity.DesiredIndustry.HasValue || entity.DesiredCompanyType.HasValue
                    || entity.DesiredSalary.HasValue) {
                    ViewBag.HasCareerGoal = true;
                }

                ViewBag.HasPersonalStatement = false;
                if (!string.IsNullOrWhiteSpace(entity.PersonalStatement)) {
                    ViewBag.HasPersonalStatement = true;
                }
            }
            return PartialView();
        }
        #endregion

        #region work action
        public ActionResult WorkList(Guid? resumeId) {
            var id = resumeId ?? (Guid)Session["ResumeId"];
            var model = new WorkExperienceListModel();
            var works = _workExperienceService.GetWorkExperiences(id);
            model.WorkExperiences = works.ToList().ConvertAll<WorkExperienceModel>(PrepareWorkModel);
            model.ResumeId = id;
            return View(model);
        }

        private void SetWorkEditDropDownList(WorkExperienceModel model) {
            // 绑定公司性质下拉框
            var companyTypes = _lovService.GetLovByParentLabel("CompanyType").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.CompanyTypes = new SelectList(companyTypes, "Value", "Name", Convert.ToString(model.CompanyType));

            // 绑定行业下拉框
            var industrys = _lovService.GetLovByParentLabel("Industry").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.Industrys = new SelectList(industrys, "Value", "Name", Convert.ToString(model.Industry));

            // 职位分类
            //JobCategoryGroupList
            ViewBag.JobCategoryList = _lovService.GetLovList(LovType.JobCategory).ToList();

            //JobCategoryList
            ViewBag.SubJobCategoryList = _lovService.GetSubJobCategoryList().ToList();
            //var jobCategorys = _lovService.GetLovByParentLabel("JobCategory").Select(s =>
            //   new { s.Value, s.Name }).AsEnumerable();
            //ViewBag.JobCategorys = new SelectList(jobCategorys, "Value", "Name", Convert.ToString(model.Category1));

            // 月
            ViewBag.ListMonthStart = DropDownListHelper.GetMonthList(model.StartMonth);
            ViewBag.ListMonthEnd = DropDownListHelper.GetMonthList(model.EndMonth);
        }

        [HttpPost]
        public ActionResult WorkEdit(WorkExperienceModel model) {
            if (ModelState.IsValid) {
                if (string.IsNullOrWhiteSpace(model.StartYear) || string.IsNullOrWhiteSpace(model.StartMonth)) {
                    ModelState.AddModelError("RequiredError", "时段起始时间必须输入!");
                    SetWorkEditDropDownList(model);
                    return View(model);
                }
                if (!ValueTypeCheck.CheckDateTime(model.StartYear, model.StartMonth, "1")) {
                    ModelState.AddModelError("StartDataError", "时间输入有误!");
                    SetWorkEditDropDownList(model);
                    return View(model);
                }

                if (!string.IsNullOrWhiteSpace(model.EndMonth) || !string.IsNullOrWhiteSpace(model.EndYear)) {
                    if (!ValueTypeCheck.CheckDateTime(model.EndYear, model.EndMonth, "1")) {
                        ModelState.AddModelError("EndDataError", "时间输入有误!");
                        SetWorkEditDropDownList(model);
                        return View(model);
                    }
                }

                bool insert = false;
                var entity = _workExperienceService.GetWorkExperienceById(model.Id);
                if (entity == null) {
                    insert = true;
                    entity = new WorkExperience();
                    entity.Id = _workExperienceService.CreateId;
                    entity.ResumeId = model.ResumeId;
                    entity.DateCreated = DateTime.Now;
                }
                entity.CompanyName = model.CompanyName;
                entity.CompanyType = model.CompanyType;
                entity.Industry = model.Industry;
                entity.Department = model.Department;
                entity.Category1 = model.Category1;
                if (entity.Category1.HasValue) {
                    var parent = _lovService.GetParent(model.Category1.Value);
                    if (parent != null) {
                        entity.Category2 = parent.Value;
                    }
                }
                entity.JobTitle = model.JobTitle;
                entity.Description = model.Description;
                entity.LastUpdated = DateTime.Now;

                //年月
                entity.StartDate = DateTime.Parse(model.StartYear + "-" + model.StartMonth + "-1");
                if (!string.IsNullOrWhiteSpace(model.EndMonth) && !string.IsNullOrWhiteSpace(model.EndYear)) {
                    entity.EndDate = DateTime.Parse(model.EndYear + "-" + model.EndMonth + "-1");
                }
                entity.IsShielded = model.IsShielded;

                if (insert) {
                    _workExperienceService.InsertWorkExperience(entity);
                }
                else {
                    _workExperienceService.UpdateWorkExperience(entity);
                }
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
                return Redirect(model.ReturnUrl ?? Url.Action("WorkList", new { resumeId = entity.ResumeId }));
            }
            SetWorkEditDropDownList(model);
            return View(model);
        }

        public ActionResult WorkEdit(Guid? id, string returnUrl) {
            var model = new WorkExperienceModel();
            if (id.HasValue) {
                var entity = _workExperienceService.GetWorkExperienceById(id.Value);
                model = new WorkExperienceModel() {
                    Category1 = entity.Category1,
                    Category2 = entity.Category2,
                    CompanyName = entity.CompanyName,
                    IsOverseas = entity.IsOverseas ?? false,
                    IsShielded = entity.IsShielded ?? false,
                    CompanyType = entity.CompanyType,
                    Department = entity.Department,
                    Description = entity.Description,
                    EndDate = entity.EndDate,
                    EndYear = entity.EndDate != null ? entity.EndDate.Value.Year.ToString() : string.Empty,
                    EndMonth = entity.EndDate != null ? entity.EndDate.Value.Month.ToString() : string.Empty,
                    Id = entity.Id,
                    Industry = entity.Industry,
                    JobTitle = entity.JobTitle,
                    StartDate = entity.StartDate,
                    StartYear = entity.StartDate.Year.ToString(),
                    StartMonth = entity.StartDate.Month.ToString(),
                    ResumeId = entity.ResumeId
                };
            }
            model.ReturnUrl = returnUrl;
            SetWorkEditDropDownList(model);
            return View(model);
        }

        public ViewResult WorkAdd(Guid? resumeId, string returnUrl) {
            var model = new WorkExperienceModel();

            var id = resumeId ?? (Guid)Session["ResumeId"];

            // 采番
            model.Id = Guid.NewGuid();
            model.ResumeId = id;
            model.ReturnUrl = returnUrl;
            SetWorkEditDropDownList(model);
            return View("WorkEdit", model);
        }

        [HttpPost]
        public ActionResult WorkDelete(Guid workId, string returnUrl) {
            var entity = _workExperienceService.GetWorkExperienceById(workId);
            if (entity != null) {
                _workExperienceService.DeleteWorkExperience(entity);
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
            }
            return Redirect(returnUrl);
        }

        [NonAction]
        private WorkExperienceModel PrepareWorkModel(WorkExperience item) {
            return new WorkExperienceModel() {
                CategoryName = this._lovService.GetLovName(item.Category1 ?? 0),
                CompanyName = item.CompanyName,
                Department = item.Department,
                Description = item.Description,
                StartDate = item.StartDate,
                EndDate = item.EndDate,
                Id = item.Id,
                JobTitle = item.JobTitle
            };
        }
        #endregion

        #region Training action
        public ActionResult TrainingList(Guid? resumeId) {
            var id = resumeId ?? (Guid)Session["ResumeId"];
            var model = new TrainingListModel();
            var trainings = this._trainingService.GetTrainings(id);
            model.Trainings = trainings.ToList().ConvertAll<TrainingModel>(PrepareTrainingModel);
            model.ResumeId = id;
            return View(model);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult TrainingEdit(TrainingModel model) {
            if (ModelState.IsValid) {
                if (string.IsNullOrWhiteSpace(model.StartYear) || string.IsNullOrWhiteSpace(model.StartMonth)) {
                    ModelState.AddModelError("RequiredError", "培训起始时间必须输入!");
                    SetTrainingEditDropDownList(model);
                    return View(model);
                }
                if (!ValueTypeCheck.CheckDateTime(model.StartYear, model.StartMonth, "1")) {
                    ModelState.AddModelError("StartDataError", "时间输入有误!");
                    SetTrainingEditDropDownList(model);
                    return View(model);
                }

                if (!string.IsNullOrWhiteSpace(model.EndMonth) || !string.IsNullOrWhiteSpace(model.EndYear)) {
                    if (!ValueTypeCheck.CheckDateTime(model.EndYear, model.EndMonth, "1")) {
                        ModelState.AddModelError("EndDataError", "时间输入有误!");
                        SetTrainingEditDropDownList(model);
                        return View(model);
                    }
                }


                bool insert = false;
                var entity = _trainingService.GetTrainingById(model.Id);
                if (entity == null) {
                    insert = true;
                    entity = new Training();
                    entity.Id = _trainingService.CreateId;
                    entity.ResumeId = model.ResumeId;
                    entity.DateCreated = DateTime.Now;
                }
                entity.Course = model.Course;
                entity.Institution = model.Institution;
                entity.LastUpdated = DateTime.Now;
                entity.Location = model.Location;
                entity.Notes = model.Notes;
                entity.Qualification = model.Qualification;

                //年月
                entity.StartDate = DateTime.Parse(model.StartYear + "-" + model.StartMonth + "-1");
                if (!string.IsNullOrWhiteSpace(model.EndMonth) && !string.IsNullOrWhiteSpace(model.EndYear)) {
                    entity.EndDate = DateTime.Parse(model.EndYear + "-" + model.EndMonth + "-1");
                }

                if (insert) {
                    _trainingService.InsertTraining(entity);
                }
                else {
                    _trainingService.UpdateTraining(entity);
                }
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
                return Redirect(model.ReturnUrl ?? Url.Action("TrainingList", "Resume", new { resumeId = entity.ResumeId }));
            }
            SetTrainingEditDropDownList(model);
            return View(model);
        }

        [NonAction]
        private void SetTrainingEditDropDownList(TrainingModel model) {
            // 月
            ViewBag.ListMonthStart = DropDownListHelper.GetMonthList(model.StartMonth);
            ViewBag.ListMonthEnd = DropDownListHelper.GetMonthList(model.EndMonth);
        }

        public ActionResult TrainingEdit(Guid? id, string returnUrl) {
            var model = new TrainingModel();
            if (id.HasValue) {
                var entity = _trainingService.GetTrainingById(id.Value);
                model = new TrainingModel() {
                    Course = entity.Course,
                    EndDate = entity.EndDate,
                    EndYear = entity.EndDate != null ? entity.EndDate.Value.Year.ToString() : string.Empty,
                    EndMonth = entity.EndDate != null ? entity.EndDate.Value.Month.ToString() : string.Empty,
                    Id = entity.Id,
                    StartDate = entity.StartDate,
                    StartYear = entity.StartDate.Year.ToString(),
                    StartMonth = entity.StartDate.Month.ToString(),
                    ResumeId = entity.ResumeId,
                    Institution = entity.Institution,
                    Location = entity.Location,
                    Notes = entity.Notes,
                    Qualification = entity.Qualification
                };
            }
            model.ReturnUrl = returnUrl;
            SetTrainingEditDropDownList(model);
            return View(model);
        }

        public ViewResult TrainingAdd(Guid resumeId, string returnUrl) {
            var model = new TrainingModel();

            // 采番
            model.Id = Guid.NewGuid();
            model.ResumeId = resumeId;
            model.ReturnUrl = returnUrl;
            SetTrainingEditDropDownList(model);
            return View("TrainingEdit", model);
        }

        [HttpPost]
        public ActionResult TrainingDelete(Guid trainingId, string returnUrl) {
            var entity = _trainingService.GetTrainingById(trainingId);
            if (entity != null) {
                _trainingService.DeleteTraining(entity);
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
            }
            return Redirect(returnUrl);
        }

        [NonAction]
        private TrainingModel PrepareTrainingModel(Training item) {
            return new TrainingModel() {
                Course = item.Course,
                Institution = item.Institution,
                Location = item.Location,
                Notes = item.Notes,
                Qualification = item.Qualification,
                StartDate = item.StartDate,
                EndDate = item.EndDate,
                Id = item.Id,
            };
        }
        #endregion

        #region Skill action
        public ActionResult SkillList(Guid? resumeId) {
            var id = resumeId ?? (Guid)Session["ResumeId"];
            var model = new SkillListModel();
            var skills = this._skillService.GetSkills(id);
            model.Skills = skills.ToList().ConvertAll<SkillModel>(PrepareSkillModel);
            model.ResumeId = id;
            return View(model);
        }

        [NonAction]
        private void SetSkillDropDownList(SkillModel model) {
            // 特长分类
            var skills = _lovService.GetLovByParentLabel("Skill").Select(s =>
               new { s.Value, s.Name }).AsEnumerable();
            ViewBag.Skills = new SelectList(skills, "Value", "Name", Convert.ToString(model.SkillCode));
        }

        [HttpPost]
        public ActionResult SkillEdit(SkillModel model) {
            if (ModelState.IsValid) {
                bool insert = false;
                var entity = _skillService.GetSkillById(model.Id);
                if (entity == null) {
                    insert = true;
                    entity = new Skill();
                    entity.Id = _skillService.CreateId;
                    entity.ResumeId = model.ResumeId;
                    entity.DateCreated = DateTime.Now;
                }
                entity.SkillCode = model.SkillCode;
                entity.Subject = model.Subject;
                entity.Body = model.Body;
                entity.LastUpdated = DateTime.Now;
                if (insert) {
                    _skillService.InsertSkill(entity);
                }
                else {
                    _skillService.UpdateSkill(entity);
                }
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
                return Redirect(model.ReturnUrl ?? Url.Action("SkillList", "Resume", new { resumeId = model.ResumeId }));
            }

            SetSkillDropDownList(model);
            return View(model);
        }

        public ActionResult SkillEdit(Guid? id, string returnUrl) {
            SkillModel model = new SkillModel();
            if (id.HasValue) {
                var entity = _skillService.GetSkillById(id.Value);
                model = new SkillModel() {
                    Body = entity.Body,
                    Id = entity.Id,
                    ResumeId = entity.ResumeId,
                    SkillCode = entity.SkillCode,
                    Subject = entity.Subject
                };
            }
            model.ReturnUrl = returnUrl;

            SetSkillDropDownList(model);
            return View(model);
        }

        public ViewResult SkillAdd(Guid resumeId, string returnUrl) {
            var model = new SkillModel();

            // 采番
            model.Id = Guid.NewGuid();
            model.ResumeId = resumeId;
            model.ReturnUrl = returnUrl;
            SetSkillDropDownList(model);
            return View("SkillEdit", model);
        }

        [HttpPost]
        public ActionResult SkillDelete(Guid skillId, string returnUrl) {
            var entity = _skillService.GetSkillById(skillId);
            if (entity != null) {
                _skillService.DeleteSkill(entity);
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
            }
            //return RedirectToAction("SkillList", new { resumeId = entity.ResumeId });
            return Redirect(returnUrl);
        }

        [NonAction]
        private SkillModel PrepareSkillModel(Skill item) {
            return new SkillModel() {
                Body = item.Body,
                Subject = item.Subject,
                SkillCode = item.SkillCode,
                Id = item.Id,
                SkillName = item.SkillCode.HasValue ?
                            _lovService.GetLovName(item.SkillCode.Value) : string.Empty
            };
        }
        #endregion

        #region Certification action
        public ActionResult CertificationList(Guid? resumeId) {
            var id = resumeId ?? (Guid)Session["ResumeId"];
            var model = new CertificationListModel();
            var certifications = this._certificationService.GetCertifications(id);
            model.Certifications = certifications.ToList().ConvertAll<CertificationModel>(PrepareCertificationModel);
            model.ResumeId = id;
            return View(model);
        }

        [NonAction]
        private void SetCertificationEditDropdownList(CertificationModel model) {
            ViewBag.ListMonth = DropDownListHelper.GetMonthList(model.DateQualifiedMonth);
            var listLicense = _lovService.GetLovByParentLabel("License").Select(s => new { s.Name, s.Value }).AsEnumerable();
            ViewBag.Licenses = new SelectList(listLicense, "Value", "Name", model.QualifiedCertification);
        }

        [HttpPost]
        public ActionResult CertificationEdit(CertificationModel model) {
            if (ModelState.IsValid) {
                if (string.IsNullOrWhiteSpace(model.DateQualifiedYear) || string.IsNullOrWhiteSpace(model.DateQualifiedMonth)) {
                    ModelState.AddModelError("RequiredError", "时段起始时间必须输入!");
                    SetCertificationEditDropdownList(model);
                    return View(model);
                }
                if (!ValueTypeCheck.CheckDateTime(model.DateQualifiedYear, model.DateQualifiedMonth, "1")) {
                    ModelState.AddModelError("StartDataError", "时间输入有误!");
                    SetCertificationEditDropdownList(model);
                    return View(model);
                }

                bool insert = false;
                var entity = _certificationService.GetCertificationById(model.Id);
                if (entity == null) {
                    insert = true;
                    entity = new Certification();
                    entity.DateCreated = DateTime.Now;
                    entity.Id = _certificationService.CreateId;
                    entity.ResumeId = model.ResumeId;
                }
                entity.CertificationName = model.CertificationName;
                if (!string.IsNullOrWhiteSpace(model.DateQualifiedYear) && !string.IsNullOrWhiteSpace(model.DateQualifiedMonth)) {
                    DateTime dt = DateTime.Now;
                    var date = model.DateQualifiedYear + "-" + model.DateQualifiedMonth + "-1";
                    DateTime.TryParse(date, out dt);
                    entity.DateQualified = dt;
                }
                entity.LastUpdated = DateTime.Now;
                entity.QualifiedCertification = model.QualifiedCertification;
                entity.Score = model.Score;
                if (insert) {
                    _certificationService.InsertCertification(entity);
                }
                else {
                    _certificationService.UpdateCertification(entity);
                }
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
                return Redirect(model.ReturnUrl ?? Url.Action("CertificationList", new { resumeId = entity.ResumeId }));
            }

            SetCertificationEditDropdownList(model);
            return View(model);
        }

        public ActionResult CertificationEdit(Guid? id, string returnUrl) {
            var model = new CertificationModel();
            if (id.HasValue) {
                var entity = _certificationService.GetCertificationById(id.Value);
                model = new CertificationModel() {
                    CertificationName = entity.CertificationName,
                    DateQualified = entity.DateQualified,
                    DateQualifiedMonth = entity.DateQualified.Month.ToString(),
                    Id = entity.Id,
                    QualifiedCertification = entity.QualifiedCertification,
                    Score = entity.Score,
                    DateQualifiedYear = entity.DateQualified.Year.ToString(),
                    ResumeId = entity.ResumeId
                };
            }
            model.ReturnUrl = returnUrl;
            SetCertificationEditDropdownList(model);
            return View(model);
        }

        public ViewResult CertificationAdd(Guid resumeId, string returnUrl) {
            var model = new CertificationModel();

            // 采番
            model.Id = Guid.NewGuid();
            model.ResumeId = resumeId;
            model.ReturnUrl = returnUrl;
            SetCertificationEditDropdownList(model);
            return View("CertificationEdit", model);
        }

        [HttpPost]
        public ActionResult CertificationDelete(Guid certificationId, string returnUrl) {
            var entity = _certificationService.GetCertificationById(certificationId);
            if (entity != null) {
                _certificationService.DeleteCertification(entity);
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
            }
            return Redirect(returnUrl);
        }

        [NonAction]
        private CertificationModel PrepareCertificationModel(Certification item) {
            return new CertificationModel() {
                CertificationName = item.CertificationName,
                DateQualified = item.DateQualified,
                QualifiedCertification = item.QualifiedCertification,
                Score = item.Score,
                Id = item.Id,
                QualifiedCertificationName = item.QualifiedCertification.HasValue ?
                            _lovService.GetLovName(item.QualifiedCertification.Value) : string.Empty
            };
        }
        #endregion

        #region Education action
        public ActionResult EducationList(Guid? resumeId) {
            var id = resumeId ?? (Guid)Session["ResumeId"];
            var model = new EducationListModel();
            var educations = this._educationService.GetEducations(id);
            model.Educations = educations.ToList().ConvertAll<EducationModel>(PrepareEducationModel);
            model.ResumeId = id;
            return View(model);
        }

        [NonAction]
        private void SetEducationEditDropDownList(EducationModel model) {
            // 绑定学历下拉框
            var educationLevels = _lovService.GetLovByParentLabel("EducationLevel").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.EducationLevels = new SelectList(educationLevels, "Value", "Name", model.EducationLevel);

            // 绑定专业下拉框
            var majors = _lovService.GetLovByParentLabel("Major").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.Majors = new SelectList(majors, "Value", "Name", model.Major1);

            // 月
            ViewBag.ListMonthStart = DropDownListHelper.GetMonthList(model.StartMonth);
            ViewBag.ListMonthEnd = DropDownListHelper.GetMonthList(model.EndMonth);
        }

        [HttpPost]
        public ActionResult EducationEdit(EducationModel model) {
            if (ModelState.IsValid) {
                if (string.IsNullOrWhiteSpace(model.StartYear) || string.IsNullOrWhiteSpace(model.StartMonth)) {
                    ModelState.AddModelError("RequiredError", "在校起始时间必须输入!");
                    SetEducationEditDropDownList(model);
                    return View(model);
                }
                if (!ValueTypeCheck.CheckDateTime(model.StartYear, model.StartMonth, "1")) {
                    ModelState.AddModelError("StartDataError", "时间输入有误!");
                    SetEducationEditDropDownList(model);
                    return View(model);
                }

                if (!string.IsNullOrWhiteSpace(model.EndMonth) || !string.IsNullOrWhiteSpace(model.EndYear)) {
                    if (!ValueTypeCheck.CheckDateTime(model.EndYear, model.EndMonth, "1")) {
                        ModelState.AddModelError("EndDataError", "时间输入有误!");
                        SetEducationEditDropDownList(model);
                        return View(model);
                    }
                }

                bool insert = false;
                var entity = _educationService.GetEducationById(model.Id);
                if (entity == null) {
                    insert = true;
                    entity = new Education();
                    entity.DateCreated = DateTime.Now;
                    entity.Id = _educationService.CreateId;
                    entity.ResumeId = model.ResumeId;
                }
                entity.EducationLevel = model.EducationLevel;
                entity.SchoolName = model.SchoolName;
                entity.IsAbroad = model.IsAbroad;
                entity.Major1 = model.Major1;
                entity.Major2 = model.Major2;
                entity.OtherMajor = model.OtherMajor;

                //年月
                entity.StartDate = DateTime.Parse(model.StartYear + "-" + model.StartMonth + "-1");
                ;
                if (!string.IsNullOrWhiteSpace(model.EndMonth) && !string.IsNullOrWhiteSpace(model.EndYear)) {
                    entity.EndDate = DateTime.Parse(model.EndYear + "-" + model.EndMonth + "-1");
                }
                entity.Notes = model.Notes;
                entity.LastUpdated = DateTime.Now;
                if (insert) {
                    _educationService.InsertEducation(entity);
                }
                else {
                    _educationService.UpdateEducation(entity);
                }
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
                return Redirect(model.ReturnUrl ?? Url.Action("EducationList", new { resumeId = entity.ResumeId }));
            }
            SetEducationEditDropDownList(model);
            return View(model);
        }

        public ActionResult EducationEdit(Guid? id, string returnUrl) {
            var model = new EducationModel();
            if (id.HasValue) {
                var entity = _educationService.GetEducationById(id.Value);
                model = new EducationModel() {
                    Id = entity.Id,
                    EducationLevel = entity.EducationLevel,
                    EndDate = entity.EndDate,
                    EndYear = entity.EndDate != null ? entity.EndDate.Value.Year.ToString() : string.Empty,
                    EndMonth = entity.EndDate != null ? entity.EndDate.Value.Month.ToString() : string.Empty,
                    StartDate = entity.StartDate,
                    StartYear = entity.StartDate.Year.ToString(),
                    StartMonth = entity.StartDate.Month.ToString(),
                    ResumeId = entity.ResumeId,
                    IsAbroad = entity.IsAbroad ?? false,
                    Major1 = entity.Major1,
                    Major2 = entity.Major2,
                    Notes = entity.Notes,
                    OtherMajor = entity.OtherMajor,
                    SchoolName = entity.SchoolName
                };
            }
            model.ReturnUrl = returnUrl;
            SetEducationEditDropDownList(model);

            return View(model);
        }

        public ViewResult EducationAdd(Guid resumeId, string returnUrl) {
            var model = new EducationModel();

            // 采番
            model.Id = Guid.NewGuid();
            model.ResumeId = resumeId;
            model.ReturnUrl = returnUrl;
            SetEducationEditDropDownList(model);
            return View("EducationEdit", model);
        }

        [HttpPost]
        public ActionResult EducationDelete(Guid educationId, string returnUrl) {
            var entity = _educationService.GetEducationById(educationId);
            if (entity != null) {
                _educationService.DeleteEducation(entity);
                //更新简历修改时间
                UpdateResumeLastUpdateTime(entity.ResumeId);
            }
            return Redirect(returnUrl);
        }

        [NonAction]
        private EducationModel PrepareEducationModel(Education item) {
            return new EducationModel() {
                EndDate = item.EndDate,
                Major1Name = _lovService.GetLovName(item.Major1 ?? 0),
                Major2Name = _lovService.GetLovName(item.Major2 ?? 0),
                Notes = item.Notes,
                OtherMajor = item.OtherMajor,
                SchoolName = item.SchoolName,
                StartDate = item.StartDate,
                Id = item.Id,
            };
        }
        #endregion

        #region CareerGoal action
        public ActionResult CareerGoalList(Guid? resumeId) {
            var id = resumeId ?? (Guid)Session["ResumeId"];

            var entity = _resumeService.GetResumeById(id);

            var model = PrepareCareerGoalModel(entity);
            return View(model);
        }

        [NonAction]
        private void SetCareerGoalEditDropdownList(CareerGoalModel model) {
            // 绑定行业下拉框
            var industrys = _lovService.GetLovByParentLabel("Industry").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.Industrys = new SelectList(industrys, "Value", "Name", Convert.ToString(model.DesiredIndustry));

            // 职位分类
            //JobCategoryGroupList
            ViewBag.JobCategoryList = _lovService.GetLovList(LovType.JobCategory).ToList();

            //JobCategoryList
            ViewBag.SubJobCategoryList = _lovService.GetSubJobCategoryList().ToList();

            // 地点
            ViewBag.RegionalismList = _lovService.GetLovList(LovType.Regionalism).ToList();

            //JobCategoryList
            ViewBag.SubRegionalismList = _lovService.GetSubListByParentValue(LovType.Regionalism).ToList();
            //var jobCategorys = _lovService.GetLovByParentLabel("JobCategory").Select(s =>
            //   new { s.Value, s.Name }).AsEnumerable();
            //ViewBag.JobCategorys = new SelectList(jobCategorys, "Value", "Name", Convert.ToString(model.DesiredJobType));

            var companyTypes = _lovService.GetLovByParentLabel("CompanyType").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.CompanyTypes = new SelectList(companyTypes, "Value", "Name", Convert.ToString(model.DesiredCompanyTypeName));

            var salaryRanges = _lovService.GetLovByParentLabel("SalaryRange").Select(s =>
                new { s.Value, s.Name }).AsEnumerable();
            ViewBag.SalaryRanges = new SelectList(salaryRanges, "Value", "Name", Convert.ToString(model.DesiredSalary));

            var canStarts = _lovService.GetLovByParentLabel("CanStart").Select(s =>
               new { s.Value, s.Name }).AsEnumerable();
            ViewBag.CanStarts = new SelectList(canStarts, "Value", "Name", Convert.ToString(model.CanStart));

            ViewBag.ListMonth = DropDownListHelper.GetMonthList(model.StartOnMonth);
            ViewBag.ListDay = DropDownListHelper.GetDayList(model.StartOnDay);
        }

        [HttpPost]
        public ActionResult CareerGoalEdit(CareerGoalModel model) {
            if (ModelState.IsValid) {
                if (!string.IsNullOrWhiteSpace(model.StartOnYear) || !string.IsNullOrWhiteSpace(model.StartOnMonth) ||
                    !string.IsNullOrWhiteSpace(model.StartOnDay)) {
                    if (!ValueTypeCheck.CheckDateTime(model.StartOnYear, model.StartOnMonth, model.StartOnDay)) {
                        ModelState.AddModelError("DataError", "时间输入有误!");
                        SetCareerGoalEditDropdownList(model);
                        return View(model);
                    }
                }

                var entity = _resumeService.GetResumeById(model.Id);
                entity.DesiredCompanyType = model.DesiredCompanyType;
                entity.DesiredIndustry = model.DesiredIndustry;
                if (!string.IsNullOrWhiteSpace(model.DesiredJobTypeString)) {
                    entity.DesiredJobType = int.Parse(model.DesiredJobTypeString);
                }
                entity.DesiredLocation = model.DesiredLocation;
                entity.DesiredOccupation = model.DesiredOccupation;
                entity.DesiredSalary = model.DesiredSalary;
                entity.CurrentRevenue = model.CurrentRevenue;
                entity.CanStart = model.CanStart;
                if (!string.IsNullOrWhiteSpace(model.StartOnYear) && !string.IsNullOrWhiteSpace(model.StartOnMonth)
                    && !string.IsNullOrWhiteSpace(model.StartOnDay)) {
                    entity.StartOn = DateTime.Parse(model.StartOnYear + "-" + model.StartOnMonth + "-" + model.StartOnDay);
                }
                entity.LastUpdated = DateTime.Now;
                _resumeService.UpdateResume(entity);
                return Redirect(model.ReturnUrl ?? Url.Action("CareerGoalList", new { resumeId = entity.Id }));
            }
            SetCareerGoalEditDropdownList(model);
            return View(model);
        }

        public ActionResult CareerGoalEdit(Guid id, string returnUrl) {
            var entity = _resumeService.GetResumeById(id);

            CareerGoalModel model = new CareerGoalModel() {
                CurrentRevenue = entity.CurrentRevenue,
                DesiredCompanyType = entity.DesiredCompanyType,
                DesiredIndustry = entity.DesiredIndustry,
                DesiredJobType = entity.DesiredJobType,
                DesiredLocation = entity.DesiredLocation,
                DesiredOccupation = entity.DesiredOccupation,
                DesiredJobTypeString = Convert.ToString(entity.DesiredJobType),
                DesiredSalary = entity.DesiredSalary,
                StartOn = entity.StartOn,
                StartOnYear = entity.StartOn.HasValue ? entity.StartOn.Value.Year.ToString() : string.Empty,
                StartOnMonth = entity.StartOn.HasValue ? entity.StartOn.Value.Month.ToString() : string.Empty,
                StartOnDay = entity.StartOn.HasValue ? entity.StartOn.Value.Day.ToString() : string.Empty,
                Id = entity.Id,
                CanStart = entity.CanStart,
                ReturnUrl = returnUrl
            };

            SetCareerGoalEditDropdownList(model);
            return View(model);
        }
        #endregion

        #region PersonalStatement edit
        public ActionResult PersonalStatementEdit(Guid? id) {
            var resumeId = id ?? (Guid)Session["ResumeId"];
            var entity = _resumeService.GetResumeById(resumeId);
            ResumeModel model = new ResumeModel() {
                Id = entity.Id,
                PersonalStatement = entity.PersonalStatement
            };
            return View(model);
        }

        [HttpPost]
        public ActionResult PersonalStatementEdit(ResumeModel model) {
            var entity = _resumeService.GetResumeById(model.Id);
            entity.PersonalStatement = model.PersonalStatement;
            entity.LastUpdated = DateTime.Now;
            _resumeService.UpdateResume(entity);
            return RedirectToAction("ResumeOverview", new { Id = model.Id });
        }
        #endregion

        #region Resume Shielded
        public ActionResult ResumeShielded(PagingFilteringModel command) {
            // 设置默认的Page信息
            if (command.PageSize <= 0)
                command.PageSize = 20;
            if (command.PageNumber <= 0)
                command.PageNumber = 1;

            var id = _workcontext.CurrentUser.Id;
            var list = _shieldedCompanyService.GetShieldedCompanyByJobseekerId(id);
            var showlist = list.Select(i => new ResumeShieldedModel() {

                Id = i.Id,
                CompanyName = i.CompanyName,

            }).ToList();
            var model = new ResumeShieldedListModel() {
                ResumeShieldedModels = new PagedList<ResumeShieldedModel>(showlist, command.PageNumber - 1, _pageSize),
                PagingFilteringContext = new PagingFilteringModel(),


            };
            model.PagingFilteringContext.LoadPagedList(model.ResumeShieldedModels);
            ViewBag.CurrentAction = "ResumeShielded";
            return View(model);
        }

        [HttpPost]
        public JsonResult ResumeShieldedSearch(string companname) {
            var id = _workcontext.CurrentUser.Id;
            var list = _shieldedCompanyService.GetShieldedCompanyByJobseekerId(id).Select(i => i.CompanyId).ToList();
            var result = _companyService.GetShieldedCompany(companname).Where(i => !list.Contains(i.Id)).Select(i => new { i.Id, i.CompanyName }).Take(20).ToList();
            return Json(result);
        }

        public ActionResult PopResumeShielded() {
            return View();
        }

        [HttpPost]
        public ActionResult PopResumeShielded(string SaveIdList) {
            if (ModelState.IsValid) {
                var list = SaveIdList.Split(',').Where(i => !string.IsNullOrEmpty(i));

                foreach (var item in list) {
                    var sitem = item.Split(':');
                    var modle = new ShieldedCompany() {

                        Id = Guid.NewGuid(),
                        CompanyId = Guid.Parse(sitem[0]),
                        CompanyName = sitem[1],
                        DateCreated = DateTime.Now,
                        JobseekerId = _workcontext.CurrentUser.Id,
                        LastUpdated = DateTime.Now

                    };

                    _shieldedCompanyService.InsertShieldedCompany(modle);
                }


                Response.Write("<script>window.location = location.href ;</script>");
            }
            return RedirectToAction("ResumeShielded");
        }

        [HttpPost]
        public ActionResult ResumeShieldedDelete(string DeleteId) {
            if (!string.IsNullOrWhiteSpace(DeleteId)) {
                var entity = _shieldedCompanyService.GetShieldedCompanyById(Guid.Parse(DeleteId));
                _shieldedCompanyService.DeleteShieldedCompany(entity);
            }
            ViewBag.CurrentAction = "ResumeShielded";
            return RedirectToAction("ResumeShielded");
        }

        [HttpPost]
        public ActionResult ResumeShieldedDeleteList(string DeleteIdList) {
            var idList = DeleteIdList.Split(',').Where(item => !string.IsNullOrWhiteSpace(item));
            foreach (var id in idList) {
                var entity = _shieldedCompanyService.GetShieldedCompanyById(Guid.Parse(id));
                _shieldedCompanyService.DeleteShieldedCompany(entity);
            }
            ViewBag.CurrentAction = "ResumeShielded";
            return RedirectToAction("ResumeShielded");
        }
        #endregion

        [NonAction]
        protected void PrepareResumeModel(ResumeModel model, Resume resume) {
            model.Id = resume.Id;
            model.LastUpdated = resume.LastUpdated;
            model.PrivacyStatus = resume.PrivacyStatus;
            switch (resume.PrivacyStatus) {
                case 1:
                    model.PrivacyStatusName = "公开";
                    break;
                case 0:
                    model.PrivacyStatusName = "隐藏";
                    break;
                default:
                    model.PrivacyStatusName = "公开";
                    break;

            }
            model.ResumeName = resume.ResumeName;
            model.Views = resume.Views;
        }

        #region 更新简历更新时间
        /// <summary>
        /// 更新简历更新时间
        /// </summary>
        /// <param name="resumeId"></param>
        private void UpdateResumeLastUpdateTime(Guid resumeId) {
            var resume = _resumeService.GetResumeById(resumeId);
            resume.LastUpdated = DateTime.Now;
            _resumeService.UpdateResume(resume);
        }
        #endregion
    }
}
